
import apiType, {
    GET_WAREHOUSE_LIST,
    GET_WAREHOUSE_EXPRESS_LIST,
    GET_WAREHOUSE_EXPRESS_PLATFORM,
    GET_WAREHOUSE_EXPRESS_REGION,
    GET_WAREHOUSE_ORDINARY_EXPRESS_LIST,
    GET_WAREHOUSE_ORDINARY_EXPRESS_REGION,
    GET_WAREHOUSE_SELECTION,
    GET_ALL_WAREHOUSE_SELECTION,
    DELETE_WAREHOUSE_EXPRESS_PLATFORM,
    SET_SELECTED_WAREHOUSE
} from "@constants/ActionTypes";

const initialState = {
    warehouseList: {}, // 仓库列表
    warehouseExpressList: {},    //同城配送列表
    warehouseExpressPlatform: [],  //指定仓库同城配送平台列表
    warehouseExpressRegion: [],    //同城配送区域
    warehouseOrdinaryExpressList: {},    //普通快递列表
    warehouseOrdinaryExpressRegion: {},    //普通快递配送区域
    warehouseSelection: [],    //仓库列表下拉框
    allWarehouseSelection: [],    //仓库列表下拉框
    selectedWarehouse: null //已选择的仓库
}

export default function update(state = initialState, action) {
    const { response, params, payload } = action
    switch (action.type) {
        case apiType(SET_SELECTED_WAREHOUSE).success:
            return {
                ...state,
                selectedWarehouse: params.value,
            }
        case apiType(GET_WAREHOUSE_LIST).success:
            return {
                ...state,
                warehouseList: response,
            }
        case apiType(GET_WAREHOUSE_EXPRESS_LIST).success:
            return {
                ...state,
                warehouseExpressList: response,
            }
        case apiType(GET_WAREHOUSE_EXPRESS_LIST).success:
            return {
                ...state,
                warehouseExpressList: response,
            }
        case apiType(GET_WAREHOUSE_EXPRESS_PLATFORM).success:
            return {
                ...state,
                warehouseExpressPlatform: response.platforms
            }
        case apiType(GET_WAREHOUSE_EXPRESS_REGION).success:
            return {
                ...state,
                warehouseExpressRegion: response,
            }
        case apiType(GET_WAREHOUSE_ORDINARY_EXPRESS_LIST).success:
            return {
                ...state,
                warehouseOrdinaryExpressList: response,
            }
        case apiType(GET_WAREHOUSE_ORDINARY_EXPRESS_REGION).success:
            return {
                ...state,
                warehouseOrdinaryExpressRegion: response,
            }
        case apiType(GET_WAREHOUSE_SELECTION).success:
            return {
                ...state,
                warehouseSelection: response.warehouses,
            }
        case apiType(GET_ALL_WAREHOUSE_SELECTION).success:
            return {
                ...state,
                allWarehouseSelection: response.warehouses || [],
            }
        case apiType(DELETE_WAREHOUSE_EXPRESS_PLATFORM).success:
        default:
            return state
    }
}